package com.craftplay.dao;

import com.craftplay.model.Love;
import org.apache.ibatis.annotations.*;

import java.util.List;


@Mapper
public interface LoveMapper {

    @Insert({
            "INSERT INTO `love` (`unitId`, `userId`,`loveTime`) VALUES" +
                    " ( #{unitId,jdbcType=INTEGER},#{userId,jdbcType=INTEGER},#{loveTime,jdbcType=TIMESTAMP});"
    })
    @SelectKey(statement = "select LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = int.class)
    int addLove(Love love);

    @Select({
            "select * from  love",
            "where userId = #{userId,jdbcType=INTEGER}"
    })
    List<Love> myLove(Integer userId);

    @Select({
            "select * from  love",
            "where userId = #{userId,jdbcType=INTEGER} and  unitId = #{unitId,jdbcType=INTEGER}"
    })
    Love isLove(@Param("unitId") Integer unitId,@Param("userId") Integer userId);

    @Select({
            "select count(*) from  love",
            "where unitId = #{unitId,jdbcType=INTEGER}"
    })
    int numberLove(Integer unitId);

    @Delete({
            "delete from love",
            "where userId = #{userId,jdbcType=INTEGER} and  unitId = #{unitId,jdbcType=INTEGER}"
    })
    int delLove(Love love);
}